//
//  LFTTabViewController.m
//  Leaflet
//
//  Created by l.t.zero on 2018/8/7.
//  Copyright © 2018 Starunion. All rights reserved.
//

#import "CBTTTabBarViewController.h"
#import "BaseNavigationController.h"
#import "MainViewController.h"
#import "CBTLocalUserManager.h"
#import "WCMarketVC.h"
#import "MyViewController.h"
#import "FindViewController.h"

@interface CBTTTabBarViewController ()<UITabBarControllerDelegate>
@property (assign,nonatomic)NSInteger nowSel_tag;
@end

@implementation CBTTTabBarViewController

+(void)load {
    [[UITabBar appearance] setBarTintColor:UIColorFromRGB(0xFF5101)];
    
    [[UITabBar appearance] setTranslucent:NO];
    UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0, -0.5, ScreenNarrowSide, 0.5)];
    lineView.backgroundColor = UIColorFromRGB(0xE6E6E6);
    [[UITabBar appearance]insertSubview:lineView atIndex:0];
}

+ (void)initialize {
    //选中字体颜色
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:[UIFont systemFontOfSize:12]} forState:UIControlStateSelected];
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:[UIFont systemFontOfSize:12]} forState:UIControlStateNormal];

    //隐藏阴影线
    [[UITabBar appearance] setShadowImage:[[UIImage alloc] init]];
    if ([UIDevice currentDevice].systemVersion.floatValue >= 11.f) {
    }else {
        [UITabBar appearance].translucent = YES;
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.delegate = self;

    MainViewController *main = [[MainViewController alloc] init];
    
    BaseNavigationController *c1 = [[BaseNavigationController alloc]initWithRootViewController:main];
    c1.title = kLocalizedString(@"钱包", nil);
    c1.tabBarItem.image=[[UIImage imageNamed:kLocalizedString(@"qianbao_normal", nil)] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    c1.tabBarItem.selectedImage=[[UIImage imageNamed:kLocalizedString(@"qianbao_select", nil)] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

    c1.tabBarItem.tag =97;

    UIViewController *c2 = [[BaseNavigationController alloc]initWithRootViewController:[[WCMarketVC alloc] init]];
    c2.title = kLocalizedString(@"商城", nil);
    c2.tabBarItem.image = [[UIImage imageNamed:kLocalizedString(@"market_normal", nil)] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    c2.tabBarItem.selectedImage = [[UIImage imageNamed:kLocalizedString(@"market_select", nil)] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    c2.tabBarItem.tag =98;

    UIViewController *c3 = [[BaseNavigationController alloc]initWithRootViewController:[[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"FindVCID"]];
    c3.title = kLocalizedString(@"发现", nil);
    c3.tabBarItem.image = [[UIImage imageNamed:kLocalizedString(@"find_normal", nil)] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    c3.tabBarItem.selectedImage = [[UIImage imageNamed:kLocalizedString(@"find_select", nil)] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    c3.tabBarItem.tag =99;
    
    UIViewController *c4 = [[BaseNavigationController alloc]initWithRootViewController:[MyViewController new]];
    c4.title = kLocalizedString(@"我的", nil);
    c4.tabBarItem.image = [[UIImage imageNamed:kLocalizedString(@"wode_normal", nil)] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    c4.tabBarItem.selectedImage = [[UIImage imageNamed:kLocalizedString(@"wode_select", nil)] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    c4.tabBarItem.tag =100;

    self.viewControllers = @[c1, c2, c3, c4];
    
//    for (UITabBarItem *item in self.tabBar.items){
//        CGFloat offset = 7.0;
//        item.imageInsets = UIEdgeInsetsMake(offset, 0, -offset, 0);
//    }
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeLanguage) name:ChangeLanguageNotificationName object:nil];
}

- (void)changeLanguage {
    for (UIViewController *vc in self.viewControllers) {
        if (vc.tabBarItem.tag == 97) {
            vc.title = kLocalizedString(@"钱包", nil);
        }
        else if (vc.tabBarItem.tag == 98){
            vc.title = kLocalizedString(@"商城", nil);
        }
        else if (vc.tabBarItem.tag == 99){
            vc.title = kLocalizedString(@"发现", nil);
        }
        else if (vc.tabBarItem.tag == 100){
            vc.title = kLocalizedString(@"我的", nil);
        }
    }
}

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{
    [HFStatusView dismissStatusView];
}

- (BOOL)shouldAutorotate
{
    return NO;
}

- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}

@end
